﻿using System.Threading;

namespace Blitzcrank
{
    public class Bot
    {
        public Board blitzBoard;

        public Bot()
        {
            blitzBoard = new Board();
        }

        public void GetPoints()
        {
            for (int y = 0; y < 8; y++)
            {
                for (int x = 0; x < 8; x++)
                {
                    if (blitzBoard.board[y, x] != (int) ColorNames.Black)
                    {
                        if (y < 8)
                        {
                            if (x < 5)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y, x + 2] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y, x + 3])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle,
                                                      (blitzBoard.upperLeftCorner.X + (x*40) + 40),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                            else if (x > 2)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y, x - 2] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y, x - 3])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle,
                                                      (blitzBoard.upperLeftCorner.X + (x*40) - 40),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                        }

                        if (y > 0 && y < 7)
                        {
                            if (x < 7)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y + 1, x + 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y - 1, x + 1])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle,
                                                      (blitzBoard.upperLeftCorner.X + (x*40) + 40),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                            else if (x > 0)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y + 1, x - 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y - 1, x - 1])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle,
                                                      (blitzBoard.upperLeftCorner.X + (x*40) - 40),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                        }

                        if (y < 6)
                        {
                            if (x < 7)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y + 1, x + 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y + 2, x + 1])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle,
                                                      (blitzBoard.upperLeftCorner.X + (x*40) + 40),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                            else if (x > 0)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y + 1, x - 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y + 2, x - 1])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle,
                                                      (blitzBoard.upperLeftCorner.X + (x*40) - 40),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                        }

                        if (y > 1)
                        {
                            if (x < 7)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y - 1, x + 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y - 2, x + 1])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle,
                                                      (blitzBoard.upperLeftCorner.X + (x*40) + 40),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                            else if (x > 0)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y - 1, x - 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y - 2, x - 1])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle,
                                                      (blitzBoard.upperLeftCorner.X + (x*40) - 40),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                        }

                        if (x < 8)
                        {
                            if (y < 5)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y + 2, x] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y + 3, x])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40) + 40));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                            else if (y > 2)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y - 2, x] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y - 3, x])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40) - 40));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                        }

                        if (x > 0 && x < 7)
                        {
                            if (y < 7)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y + 1, x + 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y + 1, x - 1])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40) + 40));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                            else if (y > 0)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y - 1, x + 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y - 1, x - 1])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40) - 40));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                        }

                        if (x < 6)
                        {
                            if (y < 7)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y + 1, x + 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y + 1, x + 2])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40) + 40));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                            else if (y > 0)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y - 1, x + 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y - 1, x + 2])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40) - 40));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                        }

                        if (x > 1)
                        {
                            if (y < 7)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y + 1, x - 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y + 1, x - 2])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40) + 40));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                            else if (y > 0)
                            {
                                if (blitzBoard.board[y, x] == blitzBoard.board[y - 1, x - 1] &&
                                    blitzBoard.board[y, x] == blitzBoard.board[y - 1, x - 2])
                                {
                                    Mouse.LeftClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                    (blitzBoard.upperLeftCorner.Y + (y*40)));
                                    Thread.Sleep(100);
                                    Mouse.LeftUnClick(blitzBoard.boardHandle, (blitzBoard.upperLeftCorner.X + (x*40)),
                                                      (blitzBoard.upperLeftCorner.Y + (y*40) - 40));
                                    blitzBoard.GenerateBoard();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}